home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Art⁄Graphics / Image 1.49 / Macros / Input⁄Output Macros < prev    next >
Encoding:
Text File  |  1993-03-31  |  9.9 KB  |  410 lines  |  [TEXT/ttxt]

  1. macro 'Save using Time as Name…';
  2. {Note: Colons are not allowed in file names.}
  3. var
  4.   year,month,day,hour,minute,second,DayOfWeek:integer;
  5. begin
  6.   GetTime(year,month,day,hour,minute,second,DayOfWeek);
  7.   SaveAs(year-1900:2,'-',month:2,'-',day:2,
  8.          '/',hour:2,'-'minute:2,'-',second:2);
  9. end;
  10.  
  11.  
  12. macro 'Open with selection… [O]';
  13. begin
  14.   if nPics>0 then KillRoi; {Save Selection}
  15.   Open('');                {Prompt for file name}
  16.   RestoreROI;              {Transfer selection to new window}
  17. end;
  18.  
  19.  
  20. macro 'Save All…';
  21. {
  22. Saves all currently open images in a folder using '001', '002', etc.
  23. as the file names. The save file dialog box will be displayed once
  24. (and only once) so that you can specify the folder to save the files in.
  25. Leave the file name blank(e.g. SaveAs('')) to get a dialog box for each file.
  26. }
  27. var
  28.   n:integer;
  29. begin
  30.   RequiresVersion(1.45);
  31.   for n:=1 to nPics do begin
  32.     SelectPic(n);
  33.     SaveAs(n:3);
  34.     {Export(n:3);}
  35.   end;
  36. end;
  37.  
  38.  
  39. macro 'Import FITS…';
  40. {
  41. This is an example of how to decode an image file header. In this case, the header is 2880 bytes long and bytes 266-269 contain the width(ASCII) and bytes
  42. 246-249 cantain the height. Refer to "FITS:A Flexible Image Transport System",
  43. Astronomy and Astrophysics Supplement Series 44, 1981, 363-370.
  44. }
  45. var
  46.   width,height,offset,i,d,m:integer;
  47. begin
  48.   width:=512; 
  49.   height:=1;
  50.   offset:=0;
  51.   SetImport('8-bit'); 
  52.   SetCustom(width,height,offset);
  53.   Import(''); {Read in header as an image, prompting for the file name.}
  54.   if not ((GetPixel(108,0)=49) and (GetPixel(109,0)=54)) then begin
  55.     {BITPIX<>16}
  56.     PutMessage('This macro only reads 16-bit FITS files');
  57.     SelectPic(nPics); Dispose;
  58.     exit;
  59.   end;
  60.   m:=1000;
  61.   width:=0;
  62.   for i:=266 to 269 do begin
  63.     d:=GetPixel(i,0);
  64.     if d=32 then d:=48;
  65.     d:=d-48;
  66.     width:=width+d*m;
  67.     m:=m/10;
  68.   end;
  69.   m:=1000;
  70.   height:=0;
  71.   for i:=346 to 349 do begin
  72.     d:=GetPixel(i,0);
  73.     if d=32 then d:=48;
  74.     d:=d-48;
  75.     height:=height+d*m;
  76.     m:=m/10;
  77.   end;
  78.   SelectPic(nPics); {The ID of the last window opened is equal to nPics.}
  79.   Dispose;
  80.   offset:=2880;
  81.   SetImport('16-bit Signed; Calibrate; Autoscale');
  82.   SetCustom(width,height,offset);
  83.   Import('');  {No prompt this time; Import remembers the name.}
  84.   FlipVertical;
  85. end;
  86.  
  87.  
  88. macro 'Import Image TIFF File…';
  89. {
  90. As an example of how to import a foreign file format, this macro reads
  91. the TIFF files created by Image. The format of an Image TIFF file
  92. is described in Appendix E of the Image manual.
  93. }  
  94. var
  95.   width,height,offset:integer;
  96. begin
  97.   width:=768; 
  98.   height:=1;
  99.   offset:=0;
  100.   SetImport('8-bit'); 
  101.   SetCustom(width,height,offset);
  102.   Import(''); {Read in header as an image, prompting for the file name.}
  103.   if not ((GetPixel(0,0)=77) and (GetPixel(0,0)=77)) then begin  {'MM'}
  104.     PutMessage('This is not a TIFF file.');
  105.     SelectPic(nPics); Dispose;
  106.     exit;
  107.   end;
  108.   width := (GetPixel(30,0)*256) + GetPixel(31,0);
  109.   height := (GetPixel(42,0)*256) + GetPixel(43,0);
  110.   SelectPic(nPics);  {The ID of the last window opened is equal to nPics.}
  111.   Dispose;
  112.   offset:=768;
  113.   SetCustom(width,height,offset);
  114.   Import('');  {No prompt this time; Import remembers the name.}
  115. end;
  116.  
  117.  
  118. macro 'Import Multiple Images per File…';
  119. {
  120. Imports a series of 256x256 images contained in a single file, in this
  121. case an NIH Image stack with an arbitrary number of 256x256 slices.
  122. }
  123. var
  124.   offset,i,PicSize,HdrSize,width,height:integer;
  125. begin
  126.   HdrSize:= 768;
  127.   width:= 256;
  128.   height:=256;
  129.   PicSize:=width*height;
  130.   offset:=HdrSize;
  131.   SetImport('8-bit');
  132.   for I:=1 to 100 do begin  {Macro will terminate at eof}
  133.     SetCustom(width,height,offset);
  134.     Import('');
  135.     offset:=offset+PicSize;
  136.   end;
  137. end;
  138.  
  139.  
  140. macro 'Import PET…';
  141. var
  142.   offset,i,PicSize,HdrSize,width,height:integer;
  143. begin
  144.   HdrSize:= 0;
  145.   width:= 128;
  146.   height:=128;
  147.   PicSize:=width*height;
  148.   offset:=HdrSize;
  149.   SetImport('8-bit');
  150.   for I:=1 to 100 do begin  {Macro will terminate at eof}
  151.     SetCustom(width,height,offset);
  152.     Import('');
  153.     offset:=offset+PicSize;
  154.   end;
  155. end;
  156.  
  157.  
  158. macro 'Convert Files…';
  159. {
  160. Converts a set of raw data files(all in the same folder) with names
  161. in the form raw.001, raw.002, etc to TIFF or PICT.  As long as the
  162. converted files are saved in the same folder, you should
  163. only see two file dialog boxes(one for the first Import and one for
  164. the first SaveAs).
  165. }
  166. Var
  167.   i,nFiles:integer;
  168. begin
  169.   nFiles:=GetNumber('Number of files:',5);
  170.   for i:=1 to nFiles do begin
  171.     Import('raw.',i:3);
  172.     SetPicName('file',i:3);
  173.     SaveAs;
  174.     Dispose;
  175.   end;
  176. end;
  177.  
  178.  
  179. macro 'Import IPLab File';
  180. var
  181.    width,height,offset:integer;
  182. begin
  183.    width:=100; 
  184.    height:=1;
  185.    offset:=0;
  186.    SetImport('8-bit'); 
  187.    SetCustom(width,height,offset);
  188.    Import(''); {Read in header as an image, prompting for file name.}
  189.    width := (GetPixel(8,0)*256) + GetPixel(9,0);
  190.    height := (GetPixel(12,0)*256) + GetPixel(13,0);
  191.    Dispose;  
  192.    offset:=2120;  {The IPLab offset}
  193.    SetImport('16-bit Signed; Calibrate; Autoscale');
  194.    SetCustom(width,height,offset);
  195.    Import('');  {No prompt this time; Import remembers the name.}
  196. end;
  197.  
  198.  
  199. procedure ShowBioRadInfo;
  200. {Displays the contents of the 480(?) byte header at}
  201. {the end of Biorad MRC 600 Z Series files.}
  202. var
  203.   InfoSize,count:integer;
  204.   ch:string;
  205. begin
  206.   InfoSize:=480;
  207.   SetCustom(InfoSize,1,HdrSize+Width*Height);
  208.   Import('');
  209.   GetRow(0,0,InfoSize);
  210.   Dispose;
  211.   SetNewSize(460,100);
  212.   SetForeground(255);
  213.   SetBackground(0);
  214.   MakeNewWindow('Info');
  215.   SetCursor('Watch');
  216.   SetFont('Monaco');
  217.   SetText('With background; Left Justified');
  218.   SetFontSize(12);
  219.   count:=0;
  220.   MoveTo(8,20);
  221.   for i:=1 to InfoSize do begin
  222.     ch:=chr(LineBuffer[i-1]);
  223.     if (ord(ch)=13) or (count>60) then begin
  224.       writeln(ch);
  225.       count:=0;
  226.     end else begin
  227.       if (ord(ch)>=32) and (ord(ch)<=126) then begin
  228.         write(ch);
  229.         count:=count+1;
  230.       end;
  231.     end;
  232.   end;
  233. end;
  234.  
  235.  
  236. macro 'Import Biorad MRC 600 Z Series…';
  237. {
  238. Imports a Z series(multiple images per file) from a Biorad MRC 600
  239. confocal microscope.  The width, height and number of images are
  240. extracted from the first 3 16-bit word in the 76 byte header and
  241. the file name is extracted from bytes 18-23 of the header.
  242. }
  243. var
  244.   width,height,nImages,offset:integer;
  245.   HdrSize,i,start,PicSize,stack:integer;
  246.   n1,n2,n3,n4,n5,n6:string;
  247. begin
  248.   {RequiresVersion(1.48);}
  249.   width:=512; 
  250.   height:=1;
  251.   offset:=0;
  252.   SetImport('8-bit'); 
  253.   SetCustom(width,height,offset);
  254.   Import(''); {Read header}
  255.   width:=GetPixel(0,0)+GetPixel(1,0)*256;
  256.   height:=GetPixel(2,0)+GetPixel(3,0)*256;
  257.   nImages:=GetPixel(4,0)+GetPixel(5,0)*256;
  258.   n1:=chr(GetPixel(18,0));
  259.   n2:=chr(GetPixel(19,0));
  260.   n3:=chr(GetPixel(20,0));
  261.   n4:=chr(GetPixel(21,0));
  262.   n5:=chr(GetPixel(22,0));
  263.   n6:=chr(GetPixel(23,0));
  264.   Dispose;
  265.   HdrSize:= 76;
  266.   if (width<128) or (width>2048) or (height<128) or (height>2048) or (nImages<1) or (nImages>256) then begin
  267.     PutMessage('This does not seem to be a Biorad MRC 600 Z Series file.');
  268.     exit;
  269.   end;
  270.   PicSize:=width*height;
  271.   start:=GetNumber('Starting image:',1);
  272.   offset:=HdrSize+(start-1)*PicSize;
  273.   SetNewSize(width,height);
  274.   MakeNewStack(n1,n2,n3,n4,n5,n6,'[',start:1,']');
  275.   stack:=nPics;
  276.   for i:=start to start+nImages-1 do begin
  277.     SetCustom(width,height,offset);
  278.     Import('');
  279.     Invert;
  280.     ChangeValues(0,0,1);
  281.     ChangeValues(255,255,254);
  282.     offset:=offset+PicSize;
  283.     SetPicName(i:3);
  284.     SelectAll;
  285.     Copy;
  286.     Dispose;
  287.     SelectPic(stack);
  288.     if i<>start then AddSlice;
  289.     Paste;
  290.   end;
  291.   KillRoi;
  292.   ShowBioRadInfo;
  293. end;
  294.  
  295.  
  296. macro 'Import from IBAS';
  297. var
  298.    width,height,offset:integer;
  299. begin
  300.    width:=128; 
  301.    height:=1;
  302.    offset:=0;
  303.    SetImport('8-bit'); 
  304.    SetCustom(width,height,offset);
  305.    Import(''); {Read in header as an image, prompting for file name.}
  306.    width := (GetPixel(7,0)*256) + GetPixel(6,0);
  307.    height := (GetPixel(9,0)*256) + GetPixel(8,0);
  308.    Dispose(nPics);  {The ID of the last window opened = nPics.}
  309.    offset:=128;  {The IBAS offset}
  310.    SetImport('8-bit; Calibrate; Autoscale');
  311.    SetCustom(width,height,offset);
  312.    Import('');  {No prompt this time; Import remembers the name.}
  313.    Invert
  314.    SetScaling ('Bilinear');
  315.    SetScaling ('New Window');
  316.    ScaleAndRotate (0.80, 1.0, 0);
  317. end;
  318.  
  319.  
  320. macro 'Import 64x64x64 SPECT Image…';
  321. {Imports a 64x64x64x16-bit headerless SPECT image into a stack.}
  322. var
  323.   width,height,nImages,offset:integer;
  324.   HdrSize,i,PicSize,stack:integer;
  325. begin
  326.   RequiresVersion(1.48);
  327.   width:=64;
  328.   height:=64;
  329.   nImages:=64;
  330.   HdrSize:= 0;
  331.   offset:=HdrSize;
  332.   PicSize:=width*height*2;
  333.   SetNewSize(width,height);
  334.   MakeNewStack('Stack');
  335.   MoveWindow(160,40);
  336.   stack:=nPics;
  337.   SetImport('16-bit Unsigned, Swap Bytes');
  338.   {SetImportMinMax(0,2500);} {Uncomment to fix scale}
  339.   for i:=1 to nImages do begin
  340.     SetCustom(width,height,offset);
  341.     Import('');
  342.     offset:=offset+PicSize;
  343.     SelectAll;
  344.     Copy;
  345.     Dispose;
  346.     SelectPic(stack);
  347.     if i>1 then AddSlice;
  348.     Paste;
  349.    end;
  350.   KillRoi;
  351. end;
  352.  
  353.  
  354. macro 'Import 8-bit 3D Image…';
  355. var
  356.   width,height,nImages,offset:integer;
  357.   HdrSize,i,PicSize,stack:integer;
  358. begin
  359.   RequiresVersion(1.48);
  360.   width:=GetNumber('Width:',256);
  361.   height:=GetNumber('Height:',256);
  362.   nImages:=GetNumber('Depth(number of slices):',128);
  363.   HdrSize:=GetNumber('Offset(header size):',0);
  364.   offset:=HdrSize;
  365.   PicSize:=width*height;
  366.   SetNewSize(width,height);
  367.   MakeNewStack('Stack');
  368.   if width<=256 then MoveWindow(96+width,40);
  369.   stack:=nPics;
  370.   SetImport('8-bit'); 
  371.   for i:=1 to nImages do begin
  372.     SetCustom(width,height,offset);
  373.     Import('');
  374.     offset:=offset+PicSize;
  375.     SelectAll;
  376.     Invert;
  377.     Copy;
  378.     Dispose;
  379.     SelectPic(stack);
  380.     if i>1 then AddSlice;
  381.     Paste;
  382.    end;
  383.   KillRoi;
  384. end;
  385.  
  386.  
  387. macro 'Open with scale set to 100 pixels/mm [S]';
  388. {Example of a way to open images and have the}
  389. {spatial scale always set the same way.}  
  390. begin
  391.   Open('');           {or Import('')}
  392.   SetScale(100,'mm'); {Change as needed}
  393. end;
  394.  
  395.  
  396. macro 'Load Synergy Image';
  397. begin
  398.    SetImport('8-bit'); 
  399.    SetCustom(512,480,16384);
  400.    Import('');
  401.    ChangeValues(0,0,1);
  402.    ChangeValues(255,255,254);
  403.    SetPalette('Rainbow');
  404. end;
  405.  
  406.  
  407.  
  408.  
  409.  
  410.